package com.yanghang.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yanghang.service.NewsService;
import com.yanghang.dao.NewsDao;
import com.yanghang.entity.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsDao nd;
    @Override
    public PageInfo<News> selectByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<News> news = nd.selectList(null);
        return new PageInfo<>(news);
    }

    @Override
    public void insertNews(News news) {
        nd.insert(news);
    }

    @Override
    public void deleteNews(int id) {
        nd.deleteById(id);
    }

    @Override
    public List<News> selectAll() {
        return nd.selectList(null);
    }

    @Override
    public void updateNews(News news) {
    nd.updateById(news);
    }
}
